//
//  ViewController.m
//  iOSQuestionInterview
//
//  Created by FelixYin on 2017/6/10.
//  Copyright © 2017年 FelixYin. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self testOne];
}


/**
 *  注意： str and str2 不是 NSString 的成员（NSString and NSMutableString 属于类簇，使用isMemberOfClass不能取到正确的结果。原因是：由于类簇的性质，这类对象实际返回的实例有不确定性。）
 *   NSString对象可能会在运行时发现其实运作的是NSCFString(来自Core Foundation框架(C语言的实现版本),很多Cocoa对象都是如此做桥接的)
 *   总之对于类簇的判断要谨慎。
 
 */
- (void) testOne{
    
    UIView *view = [UIView new];
    UIScrollView *scrollView = [UIScrollView new];
    
    //输出 Same Class
    if ([view isKindOfClass:[UIView class]] && [scrollView isKindOfClass:[UIView class]]) {
        NSLog(@"view and scrollView is the same class");
    }else{
        NSLog(@"view and scrollView is not the same class");
    }
    
    //输出 Not Same Member
    if ([view isMemberOfClass:[UIView class]] && [scrollView isMemberOfClass:[UIScrollView class]]) {
        NSLog(@"view and scrollView is the same member");
    }else{
        NSLog(@"view and scrollView is not the same member");
    }
    
    //  注意点 str and str2 不是 NSString 的成员
    NSString *str = @"HHH";
    NSString *str2 = @"HHH";
    
    NSMutableString *mStr = [NSMutableString stringWithFormat:@"HHH"];
    
    //输出 Same Class
    if ([str isKindOfClass:[NSString class]] && [mStr isKindOfClass:[NSString class]]) {
        NSLog(@"str and mStr is the Same Class");
    }else{
        NSLog(@"str and mStr is not the same Class");
    }
    
    //输出 Not Same Member
    if ([str isMemberOfClass:[NSString class]] && [mStr isMemberOfClass:[NSString class]]) {
        NSLog(@"str and mStr is the Same Member");
    }else{
        NSLog(@"str and mStr is not the Same Member");
    }
    
    //输出 Not Same Member ( str is not the NSString member )
    if ([str isMemberOfClass:[NSString class]] && [str2 isMemberOfClass:[NSString class]]) {
        NSLog(@"str and str2 is the Same Member");
    }else{
        NSLog(@"str and str2 is not the Same Member");
    }
    
    //输出 not the same member
    if ([mStr isMemberOfClass:[NSMutableString class]]) {
        NSLog(@"mStr is the Same Member");
    }else{
        NSLog(@"mStr is not the Same Member");
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
